let http = require("http");
let fs = require("fs");
let path = require("path");
let mime = require('mime');
var add = http.createServer((req,res)=>{
    if(req.url !== "/favicon.ico"){
        if(req.url == "/"){
            fs.readFile("./index.html","utf-8",(err,data)=>{
                if(err) throw err;
                res.writeHead(200,{"Content-Type":"text/html;charset=utf-8"});
                res.write(data);
                res.end()
            })
        }else {
            let path1 = "."+req.url;  //
            let typeUrl = path.extname(path1);
            typeUrl=typeUrl.substring(1)
            fs.readFile(path1,(err,data)=>{
                if(err) throw err;
                res.writeHead(200,{"Content-Type":mime.getType(typeUrl)+";charset=utf-8"});
                res.write(data);
                res.end()
            })
        }
    }

});
add.listen(3000,function () {
    console.log(`服务器已启动，请访问http://localhost:3000`);
});
